
# ifndef __DFX_WINDOW_H__
# define __DFX_WINDOW_H__

# include "dfxCore.h"
# include "dfxKeyboard.h"

namespace DFX
{
    class WindowCallback;
    class Window;   

    struct DFX_EXPORT WINDOW_PARAMETERS
    {
        UInt32  Hwnd;
        UInt32  Left;
        UInt32  Top;
        UInt32  Width;
        UInt32  Height;
        UInt32  ColorBits;
        UInt32  DepthBits;
        UInt32  StencilBits;
        UInt32  RefreshRate;
        UInt32  FullScreen;
        UInt32  MSAA;
    };
       
    class DFX_EXPORT WindowCallback
    {
    public:

        virtual void OnCreate(Window *w) = 0;
        virtual void OnDestroy(Window *w) = 0;

        virtual void OnActivate(Window *w) = 0;
        virtual void OnDeactivate(Window *w) = 0;

        virtual void OnResize(Window *w, UInt32 width, UInt32 height) = 0;
    };

    typedef std::vector<WindowCallback*>   WindowCallbackArray;
    typedef WindowCallbackArray::iterator  WindowCallbackArrayIterator;

    class DFX_EXPORT Window
    {
    protected:

        bool                    mClosed;
        String                  mName;
        String                  mClassName;
        WINDOW_PARAMETERS       *mParameters;
        WindowCallbackArray     mCallbacks;
        Keyboard                *mKeyboard;

    public:

        Window(const String &name, const String &className)
            : mName(name), mClassName(className), mClosed(false)
        {
        }

        virtual ~Window()
        {
        }

        bool IsClosed() const
        {
            return mClosed;
        }
        
        const String& GetName() const
        {
            return mName;
        }

        const String &GetClassName() const
        {
            return mClassName;
        }

        const WINDOW_PARAMETERS* GetParameters() const
        {
            return mParameters;
        }

        Keyboard* GetKeyboard() const
        {
            return mKeyboard;
        }

        UInt32 GetNumCallbacks() const
        {
            return mCallbacks.size();
        }

        WindowCallback* GetCallback(UInt32 index) const
        {
            if (index < mCallbacks.size())
                return mCallbacks[index];

            return NULL;
        }

        void AddCallback(WindowCallback *callback)
        {
            mCallbacks.push_back(callback);
        }

        void RemoveCallback(WindowCallback *callback)
        {
            WindowCallbackArrayIterator it = mCallbacks.begin();

            while (it != mCallbacks.end())
            {
                if ((*it) == callback)
                    mCallbacks.erase(it);
                else
                    it++;
            }
        }

        virtual void SetKeyboard(Keyboard *k) = 0;

        virtual DFXRESULT Create(UInt32 handle, UInt32 width, UInt32 height) = 0;
        virtual DFXRESULT Create(WINDOW_PARAMETERS *parameters) = 0;
        virtual DFXRESULT Destroy() = 0;

        virtual void SetTitle(const String &title) = 0;
        virtual void Show() = 0;
        virtual void SwapBuffers() = 0;
    };
}

# endif